#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int n)
{
	int i = 0;
	if (n < 2)
		return false;
	for (i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

int is_huiwen(int n)
{
	int tmp = n, ret = 0;
	while (tmp)
	{
		ret = ret * 10 + tmp % 10;
		tmp /= 10;
	}
	return ret == n;
}

int main()
{
	int n, cnt = 0; cin >> n;
	for (int i = 11; i <= n; i++)
	{
		if ((is_prime(i)) && (is_huiwen(i)))
			cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}
